import dayjs from 'dayjs';
import { useTable, LIST_TYPE } from '@crud/index';
import { getLecCashList } from '@/api/crm-agency/dyj/lecturer';
import { formatParamsSelectVal } from '@/utils';

// 查询
export const statusOptions = [
  { value: 0, label: '不限' },
  { value: 1, label: '待打款' },
  { value: 2, label: '已打款' }
];
export const disabledDate = (current: string | number | Date | null | undefined) => {
  if (!current) return false;
  return !dayjs(current).isBefore(dayjs());
};
// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '讲师账号名', prop: 'name', minWidth: 160, fixed: 'left' },
    { label: '讲师手机号', prop: 'mobile', minWidth: 120 },
    { label: '打款信息', prop: 'bank_info', render: 'bank_info', minWidth: 300 },
    { label: '申请时间', prop: 'add_time', minWidth: 177, type: 'dateTime' },
    { label: '申请结算金额', prop: 'total_fee', minWidth: 120, render: (s: any) => `￥${s.row.total_fee}` },
    { label: '打款金额', prop: 'punch_fee', render: (s: any) => (s.row.punch_fee ? `￥${s.row.punch_fee}` : '--') },
    { label: '操作', align: 'center', render: 'actions', width: 120, fixed: 'right' }
  ];
  const timeChange = (values: any[]) => {
    let from = undefined;
    let to = undefined;
    if (values && values.length > 0) {
      from = values[0];
      to = values[1];
    }
    return { from, to };
  };
  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: '',
      status: 0,
      from_dt: undefined,
      to_dt: undefined,
      _dateRange: []
    },
    columns: columns,
    getParams: (params) => {
      return {
        ...params,
        ...formatParamsSelectVal([['status', 0]], params)
      };
    },
    getList: ({ data, params }: { data: Record<string, any>; params: any }) => {
      const { keyword, status, _dateRange } = data;
      let { from_dt, to_dt } = params;
      const { from, to } = timeChange(_dateRange);
      from_dt = from;
      to_dt = to;
      data = { keyword, status, from_dt, to_dt };
      return getLecCashList({ data, params });
    }
  });
};
